﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TinyROS.Messages;
using TinyROS.Exceptions;

namespace TinyROS
{
    public class CarStatusTopic : Topic<CarStatusMessage>
    {
        private CarStatusMessage Data = null;
        public CarStatusTopic()
        {
            this.Name = "CarStatusTopic";
        }
        public override CarStatusMessage Latest { get => this.Data; }

        public override Type MessageType => typeof(CarStatusMessage);

        public override void Add(CarStatusMessage msg)
        {
            this.Data = msg;
            base.OnMessageAdded(msg);
        }
    }
    public class DiffcarCourseTopic : Topic<DiffcarCourseMessage>
    {
        private List<DiffcarCourseMessage> Data = new();
        public DiffcarCourseTopic()
        {
            this.Name = "DiffcarCourseTopic";
        }
        public override DiffcarCourseMessage Latest
        {
            get
            {
                if (this.Data.Count > 0)
                {
                    return this.Data[^1];
                }
                else
                {
                    return null;
                }
            }
        }
        public override Type MessageType => typeof(DiffcarCourseMessage);
        public override void Add(DiffcarCourseMessage msg)
        {
            this.Data.Add(msg);
            base.OnMessageAdded(msg);
        }
    }
    public class MapTopic : Topic<MapMessage>
    {
        private MapMessage data = null;
        public MapTopic()
        {
            this.Name = "MapTopic";
        }
        public override MapMessage Latest => this.data;

        public override Type MessageType => typeof(MapMessage);

        public override void Add(MapMessage msg)
        {
            this.data = msg;
            base.OnMessageAdded(msg);
        }
    }
    public class Vector3DTopic : Topic<Vector3DMessage>
    {
        private Vector3DMessage data = null;
        public Vector3DTopic()
        {
            this.Name = "Vector3DTopic";
        }
        public override Vector3DMessage Latest => data;

        public override Type MessageType => typeof(Vector3DMessage);

        public override void Add(Vector3DMessage msg)
        {
            this.data = msg;
            base.OnMessageAdded(msg);
        }
    }
    public class DiffcarVelocityTopic : Topic<DiffcarVelocityMessage>
    {
        private DiffcarVelocityMessage data;
        public DiffcarVelocityTopic()
        {
            this.Name = "DiffcarVelocityTopic";
        }
        public override DiffcarVelocityMessage Latest => this.data;

        public override Type MessageType => typeof(DiffcarVelocityMessage);

        public override void Add(DiffcarVelocityMessage msg)
        {
            this.data = msg;
            base.OnMessageAdded(msg);
        }
    }
    public class ByteStreamTopic : Topic<ByteStreamMessage>
    {
        private ByteStreamMessage data = null;

        public ByteStreamTopic()
        {
            this.Name = "ByteStreamTopic";
        }
        public override ByteStreamMessage Latest => this.data;

        public override Type MessageType => typeof(ByteStreamMessage);

        public override void Add(ByteStreamMessage msg)
        {
            this.data = msg;
            base.OnMessageAdded(msg);
        }
    }
    public class CommandTopic : Topic<StringMessage>
    {
        private StringMessage data = null;
        public CommandTopic()
        {
            this.Name = "CommandTopic";
        }
        public override StringMessage Latest => this.data;

        public override Type MessageType => typeof(StringMessage);

        public override void Add(StringMessage msg)
        {
            this.data = msg;
            base.OnMessageAdded(msg);
        }
    }

}
